package com.java01.lang.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class InputStreamSnippet {

	public static void main(String[] args) {
		File file = new File("D:/readme.txt");
		InputStream is = null;
		
		try {
			is = new FileInputStream(file);
			byte[] buffer = new byte[1024];
			int length;
			while((length=is.read(buffer))!=-1){
				System.out.println(">>"+new String(buffer,0,length));
				//use a specific encoding
				//System.out.println(">>"+new String(buffer,0,length,"Big5"));
				//System.out.println(">>"+new String(buffer,0,length,"GB2312"));
				//System.out.println(">>"+new String(buffer,0,length,"UTF-8"));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		if (is != null) {
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
